import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonalIndexPage(Base):
    """
    个人中心首页
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 用户头像
        self.index_personal_cover_img = (By.XPATH, Personal.RESOURCE_ID.format("personal_icon"))

        # 用户性别icon
        self.index_personal_gender_icon = (By.XPATH, Personal.RESOURCE_ID.format("iv_personal_gender"))

        # 用户名
        self.index_personal_name_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_name"))

        # 用户手机号
        self.index_personal_phone_text = (By.XPATH, Personal.RESOURCE_ID.format("phone_number_text"))

        # 编辑个人信息按钮
        self.index_personal_edit_btn = (By.XPATH, Personal.RESOURCE_ID.format("personal_info_bt"))

        # 右侧各分类的标题, 使用时需传入对应的分类名
        self.index_list_category_title_text = (By.XPATH, Page.TEXT.format(""))

        # 右侧各分类的封面, 使用时需传入对应的分类名
        self.index_list_category_cover_img = (By.XPATH, Personal.index_list_category_cover_img.format(""))

    def get_personal_cover(self):
        """
        获取用户头像

        :return:
        """
        return self.find_element_o(self.index_personal_cover_img)

    def get_personal_gender(self):
        """
        获取用户性别icon

        :return:
        """
        return self.find_element_o(self.index_personal_gender_icon)

    def get_personal_name(self):
        """
        获取用户姓名

        :return:
        """
        return self.find_element_o(self.index_personal_name_text)

    def get_personal_phone(self):
        """
        获取用户手机号

        :return:
        """
        return self.find_element_o(self.index_personal_phone_text)

    def get_personal_edit(self):
        """
        获取用户编辑框

        :return:
        """
        return self.find_element_o(self.index_personal_edit_btn)

    def get_list_category_title(self, category_name):
        """
        获取指定分类的分类标题

        :param category_name: 分类名字
        :return:
        """
        self.index_list_category_title_text = (By.XPATH, Page.TEXT.format(category_name))
        return self.find_element_o(self.index_list_category_title_text)

    def get_list_category_cover(self, category_name):
        """
        获取指定分类的分类封面

        :param category_name: 分类名字
        :return:
        """
        self.index_list_category_cover_img = (By.XPATH, Personal.index_list_category_cover_img.format(category_name))
        return self.find_element_o(self.index_list_category_cover_img)

    def click_personal_edit(self):
        """
        点击编辑个人信息按钮

        :return:
        """
        self.click_element(self.index_personal_edit_btn)

    def click_list_category(self, category_name):
        """
        点击指定分类

        :param category_name: 分类名字
        :return:
        """
        self.index_list_category_title_text = (By.XPATH, Page.TEXT.format(category_name))
        self.click_element(self.index_list_category_title_text)

    def is_display_personal_index(self):
        """
        查看是否进入个人中心首页

        :return: bool
        """
        return self.is_display(self.index_personal_cover_img)